package com.zxk.util;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.HashMap;

/**
 * 日期工具
 *
 * @author: 舟小亢
 * @date: 2023-08-31 0:13
 */
public class DateUtil {

    private static HashMap<String, Integer> hm = new HashMap() {{
        put("MONDAY", 1);
        put("TUESDAY", 2);
        put("WEDNESDAY", 3);
        put("THURSDAY", 4);
        put("FRIDAY", 5);
        put("SATURDAY", 6);
        put("SUNDAY", 7);
    }};

    /**
     * 判断当前是否在周几~周几
     *
     * @param start 周一为1
     * @param end   周日为7
     * @return
     */
    public static boolean between(int start, int end) {
        LocalDate date = LocalDate.now();
        DayOfWeek weekday = date.getDayOfWeek();
        Integer nowDay = hm.get(weekday.toString());
        return nowDay >= start && nowDay <= end;
    }

    /**
     * 获取当前周几
     *
     * @return
     */
    public static int getNowDay() {
        LocalDate date = LocalDate.now();
        DayOfWeek weekday = date.getDayOfWeek();
        return hm.get(weekday.toString());
    }
}
